/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package rules;

import java.util.ArrayList;
import java.util.Collection;
import java.util.logging.Level;
import java.util.logging.Logger;
import types.ColoringInfo;
import types.ISudokuMatrix;
import utils.RuleHelper;

/**
 *
 * @author kostja
 */
public class ColumnOneFree implements Rule  {

    int quadrat = 0;
    public String getName() {
        return ColumnOneFree.class.getSimpleName();
    }

    public String getPicName() {
        return "images/zeile.gif"; //"Anwendbar, wenn in einer Spalte 8 Felder besetzt sind";
    }

    public boolean isApplicable(int x, int y, ISudokuMatrix matrix) {
        try {
            this.setQuadrat(x, y);
        } catch (Exception ex) {
            Logger.getLogger(ColumnOneFree.class.getName()).log(Level.SEVERE, null, ex);
        }
        System.out.println("Trying to apply rule "+ this.getName()+ " for "+x+","+y);
    int num=0;
    for(int i=0; i< matrix.getRowCount(); i++){
      if ((Integer)matrix.getElementAt(i,y) == 0){
        ++num;
      }
      if (num > 1){
        return false;
      }
    }
    System.out.println("\tRule applicable");
    return true;
    }

     /**
     *  Liefert das Kosten der Anwendung des Regels
     *  Kosten für Betrachtung des Quadrat selbst = 1
     *  Kosten für Betrachtung des direkt-benachbarten Quadrat = 2
     *  Kosten für Betrachtung des indirekt-benachbarten  (Nachbar des Nachbars)Quadrat = 3
     *  +++++++++++++
     *  + 1 + 2 + 3 +
     *  +++++++++++++
     *  + 4 + 5 + 6 +
     *  +++++++++++++
     *  + 7 + 8 + 9 +
     *  +++++++++++++
     * @param QuadratNumber
     * @return
     */
    public int getWeight(int QuadratNumber) {

        if (QuadratNumber==4 || QuadratNumber==5 || QuadratNumber==6)
        {
            return 5;
        }
        else
            return 6;
    }

    public int compareTo(Rule o) {
        if (this.getWeight(this.getQuadrat())<o.getWeight(o.getQuadrat()))
            return -1;
        else if (this.getWeight(this.getQuadrat())>o.getWeight(o.getQuadrat()))
            return 1;
        else
            return 0;
    }

    public void setQuadrat(int x, int y) throws Exception {

            this.quadrat = RuleHelper.calculateQuadratNumber(x, y);

    }

    public int getQuadrat() {
       return this.quadrat;
    }

    public ColoringInfo getCheckedUnits(int x, int y, ISudokuMatrix matrix) {
        Collection column=new ArrayList();
        column.add(y);
        ColoringInfo colInfo=new ColoringInfo();
        colInfo.setColums(column);
        return colInfo;
    }




}
